﻿using UnityEngine;
using System.Collections;

public class NaveScript : MonoBehaviour {

	public Vector2 masterVelocity = new Vector2(5,5);

	private Vector2 velocity = new Vector2(0,0);

	public GameObject joy;

	public Camera viewCamera;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		Joystick val = joy.GetComponent<Joystick> ();
		float inputY = Input.GetAxis ("Vertical");
		float inputX = Input.GetAxis ("Horizontal");

		velocity = new Vector2 (masterVelocity.x * inputX, masterVelocity.y * inputY);

		Vector3 viewPos = viewCamera.WorldToViewportPoint (transform.position);

		//if ((viewPos.x < 0.03 && velocity.x < 0.03) || (viewPos.x > 0.97 && velocity.x > 0.97))
		//	velocity.x = 0;
		//if (viewPos.y < 0.05 && velocity.y < 0.05 || (viewPos.y > 0.95 && velocity.y > 0.95))
		//	velocity.y = 0;

		//transform.Translate (viewPos);
	}

	void FixedUpdate(){
		rigidbody2D.velocity = velocity;
	}
}
